********************************************************************************
* Estimates by median split of turnout
********************************************************************************

use  "Data_temp/turnout.dta", clear

* Add official turnout data
gen turnout=.
replace turnout = 75.3 if election==1987
replace turnout = 77.7 if election==1992
replace turnout = 71.4 if election==1997
replace turnout = 59.4 if election==2001
replace turnout = 61.4 if election==2005
replace turnout = 65.1 if election==2010
replace turnout = 66.2 if election==2015
replace turnout = 68.8 if election==2017

* Split for direct effects:
gen 	turnout_above0=1 if inlist(election,1992,1997,2017,2015) // 2015 in the middle
replace turnout_above0=0 if inlist(election,2001,2005,2010)

tab turnout election if abs(age1<=24)
gen 	turnout_above1=1 if inlist(election,1992,1997,2001,2017) 
replace turnout_above1=0 if inlist(election,2005,2010,2015)




estimates clear


* t0-t1
qui forvalues x = 0/1 {

forvalues a = 0/1 {

	cap drop dummy*
	tab election if voted<. & inrange(age`x',-24,24) & age`x'!=0 & turnout_above`x'==`a', gen(dummy)
	drop dummy1
	
	rdrobust voted age`x' if age`x'!=0 & turnout_above`x'==`a', c(0) p(1)  h(24) covs(dummy*)
	est sto m`x'`a'
	estadd scalar  eff_obs=e(N_b_l)+e(N_b_r)
	
	}
	
	}


		
estout m* using "Tables/a_tb5.tex", ///
style(tex) cells (b(star fmt(%9.3f)) se(par fmt(%9.3f)))  ///
starlevels( * 0.1 ** 0.05 *** 0.01)  varlabels(RD_Estimate "\hline \\ \\ RD estimate")	  ///
stats(eff_obs, fmt(%9.0gc) labels("\hline N"))    mlabels(none	) ///
collabels(none) eql(none) notype label replace	


